//
//  ViewController.m
//  ContextRefresh
//
//  Created by YannisChou on 16/3/27.
//  Copyright © 2016年 Alibaba. All rights reserved.
//

#import "ViewController.h"
#import "KCView.h"

@interface ViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>{
    KCView *_contentView;
    NSArray *_fontSize;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self initLayout];
    
    [self addPickerView];
}

#pragma mark 布局
-(void)initLayout{
    _fontSize = @[@15,@18,@20,@22,@25,@28,@30,@32,@35,@40];
    _contentView = [[KCView alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
    _contentView.backgroundColor = [UIColor whiteColor];
    _contentView.title = @"Hello world!";
    _contentView.fontSize = [_fontSize[0] intValue];
    [self.view addSubview:_contentView];
}

#pragma mark 选择器
-(void)addPickerView{
    UIPickerView *picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 300, 320, 268)];
    picker.dataSource = self;
    picker.delegate = self;
    
    [self.view addSubview:picker];
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component{
    return _fontSize.count;
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    return  [NSString stringWithFormat:@"%@号字体",_fontSize[row]];
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    _contentView.fontSize = [[_fontSize objectAtIndex:row] intValue];
    
    // 刷新视图
    [_contentView setNeedsDisplay];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
